package com.right.health.app.ui.registered.presenter;

import com.right.health.app.base.IBasePresenter;
import com.right.health.app.bean.DateOffsetInfo;
import com.right.health.app.ui.registered.view.IChooseDoctorView;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/*
 * Created by hopeliao on 2019-09-26
 *
 */
public class ChooseDoctorPresenter extends IBasePresenter<IChooseDoctorView> {

    public List<DateOffsetInfo> getTitles() {
        String[] weekDays = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
        List<DateOffsetInfo> titles = new ArrayList<>();

        Calendar calendar = Calendar.getInstance();
        StringBuilder sb = new StringBuilder();
        StringBuilder date = new StringBuilder();

        String tabAllStartTime = "";
        String tabAllEndTime = "";

        for (int i = 0; i < 7; i++) {
            if (i>0) {
                calendar.add(Calendar.DAY_OF_MONTH, 1);
            }
            sb.delete(0, sb.length());
            date.delete(0, date.length());

            int year = calendar.get(Calendar.YEAR);
            int month = calendar.get(Calendar.MONTH) + 1;
            int day = calendar.get(Calendar.DAY_OF_MONTH);

            date.append(year).append("-").append(month).append("-").append(day);

            int w = calendar.get(Calendar.DAY_OF_WEEK) - 1;
            if (w < 0) {
                w = 0;
            }
            if(i == 0) {
                tabAllStartTime = date.toString();
            }
            if(i == 6) {
                tabAllEndTime = date.toString();
            }
            sb.append(weekDays[w])
                    .append("\n")
                    .append(month < 10 ? "0" + month : month)
                    .append("-")
                    .append(day< 10 ? "0" + day : day);

            titles.add(new DateOffsetInfo(sb.toString(), date.toString(), date.toString()));
        }
        titles.add(0, new DateOffsetInfo("全部", tabAllStartTime, tabAllEndTime));
        return titles;
    }



}
